package com.setup.trac.controller;

import java.math.BigDecimal;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.SimpleFormController;

import com.setup.trac.dao.DAOService;
import com.setup.trac.pojo.StoricoTicket;
import com.setup.trac.pojo.Tickets;
import com.setup.trac.pojo.TipoIntervento;
import com.setup.trac.service.SearchService;

public class TipoInterventoController extends SimpleFormController {
	
	private DAOService daoService ;
	private SearchService searchService;
	
	@Override
	protected ModelAndView onSubmit(HttpServletRequest request,
			HttpServletResponse response, Object command, BindException errors)
			throws Exception {
		TipoIntervento tipoIntervento = (TipoIntervento) command;
		ModelAndView mv = new ModelAndView(getSuccessView());
		Tickets t = (Tickets) request.getSession(false).getAttribute("ticketClosed");
		StoricoTicket st = (StoricoTicket) request.getSession(false).getAttribute("storicoFatturato");
		t.setIdTipoIntervento(tipoIntervento.getIdIntervento());
		daoService.update(t);
		
		st.setFatturare(request.getParameter("daFatturare")!=null);
		daoService.update(st);
		request.getSession().setAttribute("nextPage", "/search.do");

		return mv;
	}

	@Override
	protected ModelAndView showForm(HttpServletRequest request,
			HttpServletResponse response, BindException errors, Map controlModel)
			throws Exception {
		ModelAndView mav =  super.showForm(request, response, errors, controlModel);
		
		
		
		return mav;
	}

	public DAOService getDaoService() {
		return daoService;
	}

	public void setDaoService(DAOService daoService) {
		this.daoService = daoService;
	}

	public SearchService getSearchService() {
		return searchService;
	}

	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}


	
	
}
